<template>
  <div class="manager-dashboard">

    <!-- 统计卡片网格 -->
    <div class="stats-grid">
      <div class="stat-card" v-for="stat in statsData" :key="stat.title">
        <div class="stat-header">
          <span class="stat-title">{{ stat.title }}</span>
          <div class="stat-icon"></div>
        </div>
        <div class="stat-value">{{ stat.value }}</div>
        <div class="stat-change">{{ stat.change }}</div>
      </div>
    </div>

    <!-- 图表区域 -->
    <div class="charts-container">
      <div class="chart-card">
        <div class="chart-header">
          <h3 class="chart-title">营业趋势图</h3>
          <div class="time-tabs">
            <button 
              v-for="tab in timeTabs" 
              :key="tab.key"
              class="time-tab"
              :class="{ active: activeTimeTab === tab.key }"
              @click="setActiveTimeTab(tab.key)"
            >
              {{ tab.label }}
            </button>
          </div>
        </div>
        <div class="chart-placeholder">
          📈 营业额 & 订单量趋势图
        </div>
      </div>

      <div class="chart-card">
        <div class="chart-header">
          <h3 class="chart-title">打手业绩排行</h3>
          <div class="time-tabs">
            <button 
              v-for="tab in performanceTabs" 
              :key="tab.key"
              class="time-tab"
              :class="{ active: activePerformanceTab === tab.key }"
              @click="setActivePerformanceTab(tab.key)"
            >
              {{ tab.label }}
            </button>
          </div>
        </div>
        <div class="chart-placeholder">
          📊 打手业绩柱状图
        </div>
      </div>
    </div>

    <!-- 底部监控区域 -->
    <div class="monitoring-section">
      <div class="monitoring-card">
        <h3 class="monitoring-title">进行中订单监控</h3>
        <div 
          v-for="order in activeOrders" 
          :key="order.id"
          class="order-item"
          :class="order.statusClass"
        >
          <div class="order-info">
            <h4>{{ order.title }}</h4>
            <p>{{ order.description }}</p>
          </div>
          <span class="order-status" :class="'status-' + order.statusClass">
            {{ order.status }}
          </span>
        </div>
      </div>

      <div class="monitoring-card">
        <h3 class="monitoring-title">打手状态快览</h3>
        <div class="worker-status-grid">
          <div 
            v-for="worker in workerStatus" 
            :key="worker.id"
            class="worker-status-item"
            @click="handleWorkerClick(worker)"
          >
            <span class="worker-name">{{ worker.name }}</span>
            <span class="status-dot" :class="'status-' + worker.status"></span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

// 响应式数据
const activeTimeTab = ref<string>('30days')
const activePerformanceTab = ref<string>('day')

// 统计数据
const statsData = ref([
  { title: '今日订单数', value: '24', change: '↗ +12% 较昨日' },
  { title: '今日营业额', value: '¥1,280', change: '↗ +18% 较昨日' },
  { title: '在线打手数', value: '6/12', change: '当前在线/总数' },
  { title: '待分配订单', value: '3', change: '需要立即处理' }
])

// 时间选项卡配置
const timeTabs = [
  { key: '7days', label: '近7天' },
  { key: '30days', label: '近30天' },
  { key: '3months', label: '近3个月' }
]

const performanceTabs = [
  { key: 'day', label: '日' },
  { key: 'week', label: '周' },
  { key: 'month', label: '月' }
]

// 活跃订单
const activeOrders = ref([
  {
    id: 1,
    title: '三角洲陪玩 - 2小时',
    description: '客户：王小明 | 打手：小李 | 已进行：1.5小时',
    status: '进行中',
    statusClass: 'progress'
  },
  {
    id: 2,
    title: '竞技陪练 - 1小时',
    description: '客户：李华 | 打手：小王 | 已进行：1.2小时',
    status: '即将超时',
    statusClass: 'warning'
  },
  {
    id: 3,
    title: '休闲陪玩 - 3小时',
    description: '客户：张玲 | 16:00 下单 | 待分配',
    status: '待分配',
    statusClass: 'pending'
  }
])

// 打手状态
const workerStatus = ref([
  { id: 1, name: '小李', status: 'working' },
  { id: 2, name: '小王', status: 'working' },
  { id: 3, name: '小张', status: 'idle' },
  { id: 4, name: '小赵', status: 'idle' },
  { id: 5, name: '小陈', status: 'rest' },
  { id: 6, name: '小刘', status: 'offline' }
])

// 方法
const setActiveTimeTab = (key: string) => {
  activeTimeTab.value = key
  ElMessage.success(`切换到${timeTabs.find(tab => tab.key === key)?.label}视图`)
}

const setActivePerformanceTab = (key: string) => {
  activePerformanceTab.value = key
  ElMessage.success(`切换到${performanceTabs.find(tab => tab.key === key)?.label}视图`)
}


const handleWorkerClick = (worker: any) => {
  ElMessage.success(`快速分配订单给 ${worker.name}`)
}

// 组件挂载
onMounted(() => {
  console.log('店长工作台已加载')
})
</script>

<style scoped lang="scss">
.manager-dashboard {
  position: relative;
  width: 100%;
  height: 100%;
}


/* 统计卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(25px);
  border-radius: 24px;
  padding: 28px;
  border: 1px solid rgba(255,255,255,0.4);
  box-shadow: 
    0 12px 40px rgba(0, 0, 0, 0.2),
    0 0 60px rgba(255, 255, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    transform: rotate(-45deg);
    transition: all 0.6s ease;
    opacity: 0;
  }

  &:hover {
    transform: translateY(-12px) scale(1.02);
    box-shadow: 
      0 20px 80px rgba(0, 0, 0, 0.25),
      0 0 40px rgba(255, 255, 255, 0.1),
      inset 0 1px 0 rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.2);

    &::before {
      opacity: 1;
      transform: rotate(-45deg) translateX(100%);
    }
  }
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.stat-title {
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3);
  background-size: 400% 400%;
  animation: gradientShift 4s ease infinite;
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);

  &::after {
    content: '';
    position: absolute;
    top: 10%;
    left: 20%;
    width: 30%;
    height: 30%;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    filter: blur(2px);
  }
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.stat-value {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, #667eea, #764ba2, #f093fb);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  animation: textGlow 3s ease-in-out infinite;
}

@keyframes textGlow {
  0%, 100% { 
    background-position: 0% 50%;
    text-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
  }
  50% { 
    background-position: 100% 50%;
    text-shadow: 0 0 30px rgba(118, 75, 162, 0.8);
  }
}

.stat-change {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  background: rgba(39, 174, 96, 0.2);
  padding: 4px 8px;
  border-radius: 12px;
  backdrop-filter: blur(10px);
}

/* 图表区域 */
.charts-container {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

.chart-card {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(25px);
  border-radius: 24px;
  padding: 28px;
  border: 1px solid rgba(255,255,255,0.3);
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.15),
    0 0 60px rgba(255, 255, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  position: relative;
  overflow: hidden;
  transition: all 0.4s ease;

  &::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.8s ease;
  }

  &:hover::after {
    left: 100%;
  }
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.chart-title {
  font-size: 18px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.time-tabs {
  display: flex;
  gap: 8px;
}

.time-tab {
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  cursor: pointer;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 600;
  transition: all 0.3s ease;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);

  &.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transform: translateY(-2px);
  }
}

.chart-placeholder {
  height: 200px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.8);
  font-size: 16px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
}

/* 底部监控区域 */
.monitoring-section {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

.monitoring-card {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(25px);
  border-radius: 24px;
  padding: 28px;
  border: 1px solid rgba(255,255,255,0.3);
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.15),
    0 0 60px rgba(255, 255, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  position: relative;
  overflow: hidden;
}

.monitoring-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.order-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  border-left: 4px solid transparent;
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);

  &.progress { border-left-color: #4ECDC4; }
  &.warning { border-left-color: #F39C12; }
  &.pending { border-left-color: #E74C3C; }
}

.order-info h4 {
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.order-info p {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.order-status {
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pending {
  background: rgba(231, 76, 60, 0.1);
  color: #E74C3C;
}

.status-progress {
  background: rgba(78, 205, 196, 0.1);
  color: #4ECDC4;
}

.status-warning {
  background: rgba(243, 156, 18, 0.1);
  color: #F39C12;
}

/* 打手状态网格 */
.worker-status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.worker-status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);

  &:hover {
    background: rgba(78, 205, 196, 0.1);
    transform: translateY(-2px);
  }
}

.worker-name {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;

  &.status-idle { background: #27AE60; }
  &.status-rest { background: #F39C12; }
  &.status-working { background: #3498DB; }
  &.status-offline { background: #95A5A6; }
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .charts-container,
  .monitoring-section {
    grid-template-columns: 1fr;
  }
}
</style>